/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "Resource.h"
#include "physfs.h"

#include "Kernel.h"

extern Kernel* g_kernel;

Resource::Resource(void)
{
    loadArc_f.Set( this );
}

/** Initialize the VFS */
bool Resource::Init()
{
    g_kernel->GetConsole()->AddCommand( &loadArc_f, "load" );
    return PHYSFS_init(NULL);
}

/** Close off any open streams */
void Resource::Shutdown()
{
    PHYSFS_deinit();
    g_kernel->GetConsole()->RemoveCommand( "load" );
}

/** Load a zip archive into memory */
void Resource::LoadArchive( const std::string &zip )
{
    PHYSFS_addToSearchPath( zip.c_str(), 0); // load to the front
}


/** Load an image into mem */
Image Resource::LoadSingleImage(const std::string &s)
{
    return m_textureLoader.CreateImage( s );
}

/** Load a  sub-image into mem */
Image Resource::LoadImages(const std::string &s, int r, int c)
{
    return m_textureLoader.CreateImage( s, r, c );
}

/** Load a sound file */
SoundSource* Resource::LoadSound( const std::string &s )
{
    return g_kernel->GetSound()->LoadSound( s );
}


/** Number of sounds in cache */
int Resource::Sounds()
{
    return g_kernel->GetSound()->NumSounds();
}
/** Number of textures in cache */
int Resource::Textures()
{
    return m_textureLoader.NumTextures();
}

Resource::~Resource(void)
{

}
